@extends('admin.formLayout')
@section('title','开屏设置')
@section('barName','开屏设置')
@section('content')
    <form class="layui-form" action="{{route('admin.coopen.coopen.update')}}" method="post">
                    <div class="layui-row">
                        <div class="layui-col-md8">
                            {{csrf_field()}}
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">首页视频<span style="color:red">*</span></label>
                            <div class="layui-input-block">
                                <ul id="step1container">
                                    @if(old('video_id'))
                                        <li><p>视频名称：{{$video->video_title}}</p></li>
                                    @elseif(isset($model)&&$model->video)
                                        <li>
                                            {{$model->video->post_title}}
                                        </li>
                                    @endif

                                </ul>
                                <input lay-verify="required" type="hidden" name="video_id" value="@if(old('video_id'))old('video_id')@else{{$model->video_id or ''}}@endif"/>
                            </div>
                            <div class="layui-input-block">
                                <button class="layui-btn" id="step1" type="button"><i class="layui-icon">&#xe654;</i>选择视频</button>

                            </div>
                        </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="form">立即提交</button>
                                    <button type="button"  onclick="javascript:location.href='{{route('admin.coopen.coopen')}}'" class="layui-btn layui-btn-primary">返回</button>
                                </div>
                            </div>
                        </div>
                    </div>

    </form>
@endsection
@section('script')
    <script>
        var video = {};
        layui.use(['element','form','layer','upload','jquery'], function(){
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var upload = layui.upload;
            var $ = layui.jquery;

            form.on('submit(*)',function(data){
                console.log(data);
                return false;
            });
            //一些事件监听
            element.on('tab(posts)', function(data){
            });
            //选择套餐
            $(document).on('click','#step1',function () {
                layer.open({
                    type: 2,
                    title: '选择套餐',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['90%', '100%'],
                    resize:true,
                    content: '{{route('admin.coopen.coopen.videoList')}}', //iframe的url
                    success:function () {
                        video = {}
                    },
                    end:function () {
                        if(video&&video.id!=undefined){
                            str = '<li>';
                            str +='<p>视频名称：'+video.post_title+'</p>'
                            str +='</li>';
                            $('#step1container').html(str);
                            $('#step1').text('重新选择视频');
                            $('[name=video_id]').val(video.id);
                        }
                    }
                });
            })
            @if (count($errors) > 0)
                @foreach ($errors->all() as $error)
                    layer.msg('{{$error}}',{'icon':2});
            @break
            @endforeach
            @endif

        });
    </script>
@endsection